package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.CategoryAttributeTemplateAddNewDTO;
import cn.tedu.csmall.product.service.ICategoryAttributeTemplateService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 处理类别与属性模板的关联相关请求的控制器
 *
 * @author stephen
 * @version 0.0.1
 */
@Slf4j
@RestController
@RequestMapping("categoryattributetemplates")
@Api(tags = "08.类别与属性模板的关联管理模块")
public class CategoryAttributeTemplateController {

    public CategoryAttributeTemplateController() {
        log.info("创建控制器：CategoryAttributeTemplateController");
    }

    @Autowired
    private ICategoryAttributeTemplateService categoryAttributeTemplateService;

    @ApiOperation("添加类别与属性模板的关联")
    @ApiOperationSupport(order = 10)
    @PostMapping("/add-new")
    public JsonResult addNew(CategoryAttributeTemplateAddNewDTO categoryAttributeTemplateAddNewDTO){
        log.debug("开始处理【添加类别与属性模版的关联】的请求：{}", categoryAttributeTemplateAddNewDTO);
        categoryAttributeTemplateService.addNew(categoryAttributeTemplateAddNewDTO);
        return JsonResult.ok();
    }


    @PostMapping("/{id:[0-9]+}/deleteById")
    @ApiOperation("根据id删除类别与属性模板的关联数据")
    @ApiImplicitParam(name = "id",value = "类别与属性模板关联id",dataType = "Long",required = true)
    public JsonResult deleteById(Long id){
        log.debug("开始处理【删除类别与属性模版的关联】的请求：id={}", id);
        categoryAttributeTemplateService.deleteById(id);
        return JsonResult.ok();
    }
}
